package com.hxzy.controller;

import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author gityyge
 * @Description 发送延迟任务/定时任务
 * @Date 2023/8/10 11:12
 * @Version 1.0
 */
@RestController
public class ProducerDelayMessageController {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    /**
     *  发送同步延迟消息
     * @param message
     * @return
     */
    @PostMapping(value = "/send/delay")
    public SendResult sendMessageDelay(String message){
        //1、创建一个消息
        Message<String> messageObj = MessageBuilder.withPayload(message).build();


        //delayTimeLevel：1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
        //2、向rocketmq发送消息
        // 目的地  destination – formats: `topicName:tags`    主题名称：标识(过滤字符)
        // 消息对象    Message
        // 消息内容对象
        SendResult sendResult = this.rocketMQTemplate.syncSend("hxzy_test:A", messageObj,3000L,4);

        return sendResult;
    }


}
